package com.tao.ifdemo2;

import java.util.Scanner;

public class IfDemo8 {
    public static void main(String[] args) {
        int hour, minute, second;
        Scanner input = new Scanner(System.in);
        System.out.println("请输入小时");
        hour = input.nextInt();
        // 判断格式
        if(hour > 23 || hour < 0){
            System.err.println("输入的小时格式有误");
        }
        System.out.println("请输入分钟");
        minute = input.nextInt();
        // 判断格式
        if(minute > 59 || minute < 0){
            System.err.println("输入的分钟格式有误");
        }
        System.out.println("请输入秒");
        second = input.nextInt();
        // 判断秒格式
        if(second > 59 || second < 0){
            System.err.println("输入的秒格式有误");
        }
        // 完成下一秒操作
        second++;
        // if嵌套判断到达60操作
        if(second == 60){
            minute++;
            second = 0;
            if(minute == 60){
                hour++;
                minute = 0;
                if(hour == 24){
                    hour = 0;
                }
            }
        }
        // 修改输出格式
        String hourStr = hour + "";
        String minuteStr = minute + "";
        String secondStr = second + "";
        if(hour == 0){
            hourStr = "0" + hourStr;
        }
        if (minute == 0){
            minuteStr = "0" + minuteStr;
        }
        if (second == 0){
            secondStr = "0" + secondStr;
        }
        // 输出
        System.out.println(hourStr + "时" + minuteStr + "分" + secondStr + "秒");
    }
}
